home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / cops / cops_104 / perl / dev.chk < prev    next >
Encoding:
Text File  |  1992-03-10  |  2.3 KB  |  104 lines

  1. #!/bin/sh -- need to mention perl here to avoid recursion
  2. 'true' || eval 'exec perl -S $0 $argv:q';
  3. eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
  4. & eval 'exec /usr/bin/perl -S $0 $argv:q'
  5.         if 0;
  6.  
  7. #
  8. #  dev.chk [-g]
  9. #
  10. #   This shell script checks the permissions of all devs listed in the
  11. # file /etc/fstab (the "mount" command would be a preferable way of
  12. # getting the file system name, but the syntax of the output is variable
  13. # from machine to machine), and flags them if they are readable by using
  14. # the "is_readable" command.  It also checks for unrestricted NFS
  15. # mountings.  By default, dev_check will flag devs only if world readable
  16. # or writable.  The -g option tells it to print out devs that are also
  17. # group readable/writable.
  18. #   As an aside, the fact that NFS mounted dirs are world readable isn't
  19. # a big deal, but they shouldn't be world writable.  So do two checks here,
  20. # instead of one.
  21. #
  22. #  Two types of /etc/fstab formats I've seen so far:
  23. #
  24. # "old" --
  25. #  spec:file:type:freq:passno:name:options
  26. #      NFS are indicated by an "@"
  27. #
  28. # "new" --
  29. #  fsname dir type opts freq passno
  30. #      NFS are indicated by an ":"
  31. #
  32. # tchrist@convex.com
  33. #
  34.  
  35. require 'is_able.pl';
  36.  
  37. $MTAB    = '/etc/fstab' unless defined $MTAB;
  38. $EXPORTS = '/etc/exports' unless defined $EXPORTS;
  39. $TAB_STYLE = 'new' unless defined $TAB_STYLE;  # or 'old'  
  40.  
  41. &usage if @ARGV > 1;
  42.  
  43. sub usage { die "Usage: $0 [-g]\n"; }
  44.  
  45. if (@ARGV == 1) {
  46.     if ($ARGV[0] eq '-g') {
  47.     $group++;
  48.     } else {
  49.     &usage;
  50.     } 
  51.  
  52.  
  53. open MTAB || die "can't open $MTAB: $!\n";
  54.  
  55. while (<MTAB>) {
  56.     next if /^#/;
  57.     chop;
  58.     if ($TAB_STYLE eq 'new') {
  59.     ($dev, $fs) = split;
  60.     next unless $fs;
  61.     if ($dev =~ /:/) {
  62.         push(@nfs_devs, $fs);
  63.     } else {
  64.         push(@local_devs, $dev);
  65.     } 
  66.     } else {
  67.     ($dev, $fs) = split(/:/);
  68.     next unless $fs;
  69.     if ($dev =~ /@/) {
  70.         push(@nfs_devs, $fs);
  71.     } else {
  72.         push(@local_devs, $dev);
  73.     } 
  74.     } 
  75.  
  76.  
  77. if (open EXPORTS) {
  78.     while (<EXPORTS>) {
  79.     next if /^\s*#/;
  80.     next if /\S\s+\S/;
  81.     next if /^\s*$/;
  82.     chop;
  83.     print "Warning!  NFS file system $_ exported with no restrictions.\n";
  84.     } 
  85.  
  86. # WARNING: we may hang if server down....
  87. #
  88. for (@nfs_devs, @local_devs) {
  89.     &is_able($_, 'w', 'w');
  90.     next unless $group;
  91.     &is_able($_, 'g', 'w');
  92.  
  93. for (@local_devs) {
  94.     &is_able($_, 'w', 'r');
  95.     next unless $group;
  96.     &is_able($_, 'g', 'r');
  97.  
  98. 1;
  99.